package com.bw.module_home.device.model

import com.bw.lib_common.entity.Res
import com.bw.module_home.device.api.DeviceApiService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

//class DeviceRepository:BaseRepository<DeviceApiService>() {
//    override fun createApiServer(): DeviceApiService =  OkHttpClientManager.retrofitInstance.create(
//        DeviceApiService::class.java)
//    suspend fun getDeviceList():Res<DeviceEntity> = apiService.getDevice()
//
//    suspend fun addDevice(deviceEntityItem: DeviceEntityItem):Res<DeviceEntityItem>{
//        return apiService.addDevice(deviceEntityItem)
//    }
//}
class DeviceRepository @Inject constructor() {
    @Inject
    @DeviceModule.CommonHomeApi
    lateinit var api: DeviceApiService

    fun getDeviceList(): Flow<Res<DeviceEntity>> = flow {
        emit(api.getDevice())
    }.flowOn(Dispatchers.IO)
    fun addDevice(deviceEntityItem: DeviceEntityItem): Flow<Res<DeviceEntityItem>> = flow {
        emit(api.addDevice(deviceEntityItem))
    }.flowOn(Dispatchers.IO)
}